package rendava;


/**
 * Tree. Used to connect the nodes in a tree holds the root node which contains other nodes.  
 * @author 
 * @version 1.0
 */
public class Tree 
{
	private Tag rootElement;
	
	/**
	 * Creates a tree and passes the root tag into it.
	 *  @param root passes tag which becomes root tag 
	 */
	public Tree( Tag root )
	{
		rootElement =root;
		
	}
	
	private Tree returnList()
	{
		//TODO decide if this is needed
		return this;
	}
	
	public String toString()
	{
		//TODO decide if this is needed
		return "Parent = " + rootElement.getClass().getName();
	}
	
	/**
	 * adds a tag to the tree
	 *  @param newtag the tag to be added to tree
	 *  @param rootTag the parent of the tag to be added.
	 */
	public void addTag(Tag newTag, Tag rootTag)
	{
		newTag.setparent(rootTag);
		rootTag.setChild(newTag);
	}
	
	/**
	 * Gets the child of a tag
	 *  @param referencetag tag that will be used to get child
	 *  @return Tag returns the child of a tag
	 */
	public Tag getChildTag(Tag referenceTag)
	{
		return referenceTag.getchild();
	}
	
	/**
	 * Gets the parent of the tag 
	 *  @param referenceTag  tag which would be used to get parent
	 *  @return Tag returns the parent of a tag
	 */
	public Tag getParentTag(Tag referenceTag)
	{
		return referenceTag.getparent();
	}
	
	/**
	 * gets the sibling of a tag
	 *  @param referenceTag  tag which would be used to get sibling
	 *  @return Tag returns the sibling of a tag
	 */
	public Tag getSiblingTag(Tag referenceTag)
	{
		// gets the parent of the current tag and uses reference tag 
		// to search for sibling(the tag which is to the right of the tag in the parameters).
		return referenceTag.getparent().getSibling(referenceTag);
	}
	
	/**
	 * gets the root element in the tree
	 *  @return Tag returns the root element in  a tree 
	 */
	public Tag getRootElement() {
		// returns the root element of this tree.
		return rootElement;
	}

}
